package com.demo.v3;

public class RbtNode<T extends Comparable<T>> {

    public static final boolean RED = false;
    public static final boolean BLACK = true;

    /**
     * 节点颜色
     */
    public boolean color;
    /**
     * 节点数据
     */
    public T key;
    /**
     * 此节点左侧节点
     */
    public RbtNode<T> left;
    /**
     * 此节点右侧节点
     */
    public RbtNode<T> right;
    /**
     * 此节点父节点
     */
    public RbtNode<T> parent;

    public RbtNode(T key, boolean color, RbtNode<T> parent,
                   RbtNode<T> left, RbtNode<T> right) {
        this.key = key;
        this.color = color;
        this.parent = parent;
        this.left = left;
        this.right = right;
    }

    @Override
    public String toString() {
        return "" + key + (this.color == RED ? "(R)" : "B");
    }
}
